﻿using System.Collections.Generic;
using System.Web.Mvc;

namespace Genesis.Infrastructure.Web.Controllers
{

    using Genesis.Infrastructure.Application;

    [HandleError]
    public abstract class BaseController : Controller
    {

        [NonAction]
        protected void ConsumeError(string propertyName, string errorMessage)
        {

            ModelState.AddModelError(propertyName, errorMessage);

        }

        [NonAction]
        protected void ConsumeError(IValidationError validationError)
        {

            ConsumeError(validationError.PropertyName, validationError.ErrorMessage);

        }

        [NonAction]
        protected void ConsumeErrors(IEnumerable<IValidationError> validationErrors)
        {

            foreach (IValidationError validationError in validationErrors)
                ConsumeError(validationError);

        }

    }

}